﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YArchitech.Revit.RevitExtension;

namespace YArchitech.HVAC
{
	internal class LayRadiatorDrawUtility
	{
		public static List<Line> Draw(Autodesk.Revit.DB.View view, XYZ startPoint, XYZ currentPoint, bool freeLay)
		{
			List<Line> list = new List<Line>();
			try
			{
				double num = 1.6404199475065617 * (double)view.Scale / 100.0;
				double num2 = 0.20341207349081364 * (double)view.Scale / 100.0;
				XYZ xyz = new XYZ();
				XYZ xyz2 = new XYZ();
				XYZ xyz3 = new XYZ();
				XYZ endPoint = new XYZ();
				if (freeLay)
				{
					xyz = currentPoint - view.RightDirection * num / 2.0;
					xyz2 = currentPoint + view.RightDirection * num / 2.0;
					xyz3 = xyz + view.UpDirection * num2;
					endPoint = xyz2 + view.UpDirection * num2;
				}
				else
				{
					XYZ xyz4 = (startPoint - currentPoint).Normalize();
					XYZ xyz5 = new XYZ(-xyz4.Y, xyz4.X, xyz4.Z);
					xyz = startPoint - xyz5 * num / 2.0;
					xyz2 = startPoint + xyz5 * num / 2.0;
					xyz3 = xyz + xyz4 * num2;
					endPoint = xyz2 + xyz4 * num2;
					list.Add(YJKLineEx.YJKGetBound(startPoint, currentPoint));
				}
				list.Add(YJKLineEx.YJKGetBound(xyz, xyz2));
				list.Add(YJKLineEx.YJKGetBound(xyz, xyz3));
				list.Add(YJKLineEx.YJKGetBound(xyz2, endPoint));
				list.Add(YJKLineEx.YJKGetBound(xyz3, endPoint));
			}
			catch (Exception ex)
			{
				ex.ToString();
				throw ex;
			}
			return list;
		}
	}
}
